import '../utils/date_utils.dart';
import 'paging_model.dart';
import 'result_model.dart';

/// 学校班级课表:查询:请求
class SchoolClassTimetableQueryReq extends PagingQueryReq {
  final String schoolId, semesterId, classId, title;
  final int gradeVal, status;

  SchoolClassTimetableQueryReq({
    required this.schoolId,
    required this.semesterId,
    required this.gradeVal,
    required this.classId,
    required this.title,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['semesterId'] = semesterId;
    map['gradeVal'] = gradeVal;
    map['classId'] = classId;
    map['title'] = title;
    map['status'] = status;
    return map;
  }
}

/// 学校班级课表:查询:响应
class SchoolClassTimetableQueryRes
    extends PagingQueryRes<SchoolClassTimetableItemRes> {
  SchoolClassTimetableQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory SchoolClassTimetableQueryRes.fromModel(final ResultModelRes res) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => SchoolClassTimetableItemRes.fromMap(row),
    );
    return SchoolClassTimetableQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

/// 学校班级课表:数据项:响应
class SchoolClassTimetableItemRes {
  final String id, title, semesterId, classId, remark;
  final int gradeVal, status;
  final DateTime? createdAt;

  const SchoolClassTimetableItemRes({
    required this.id,
    required this.title,
    required this.semesterId,
    required this.gradeVal,
    required this.classId,
    required this.remark,
    required this.status,
    required this.createdAt,
  });

  factory SchoolClassTimetableItemRes.fromMap(final Map<String, dynamic> map) =>
      SchoolClassTimetableItemRes(
        id: map['id'] ?? '',
        title: map['title'] ?? '',
        semesterId: map['semesterId'] ?? '',
        gradeVal: map['gradeVal'] ?? 0,
        classId: map['classId'] ?? '',
        remark: map['remark'] ?? '',
        status: map['status'] ?? 0,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

/// 学校班级课表:加载:响应
class SchoolClassTimetableInfoRes extends SchoolClassTimetableItemRes
    with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  SchoolClassTimetableInfoRes({
    required this.retCode,
    required this.retMessage,
    required SchoolClassTimetableItemRes item,
  }) : super(
          id: item.id,
          title: item.title,
          semesterId: item.semesterId,
          gradeVal: item.gradeVal,
          classId: item.classId,
          remark: item.remark,
          status: item.status,
          createdAt: item.createdAt,
        );

  factory SchoolClassTimetableInfoRes.fromModel(final ResultModelRes res) =>
      SchoolClassTimetableInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: SchoolClassTimetableItemRes.fromMap(res.toMap),
      );
}

/// 学校班级课表:新增:请求
class SchoolClassTimetableAddReq {
  final String schoolId, title, semesterId, classId, remark;
  final int gradeVal;

  const SchoolClassTimetableAddReq({
    required this.schoolId,
    required this.title,
    required this.semesterId,
    required this.gradeVal,
    required this.classId,
    required this.remark,
  });

  Map<String, dynamic> toMap() => {
        'title': title,
        'semesterId': semesterId,
        'gradeVal': gradeVal,
        'classId': classId,
        'remark': remark,
      };
}

class SchoolClassTimetableModifyReq {
  final String id, title, semesterId, classId, remark;
  final int gradeVal, status;

  const SchoolClassTimetableModifyReq({
    required this.id,
    required this.title,
    required this.semesterId,
    required this.gradeVal,
    required this.classId,
    required this.remark,
    required this.status,
  });

  Map<String, dynamic> toMap() => {
        'title': title,
        'semesterId': semesterId,
        'gradeVal': gradeVal,
        'classId': classId,
        'remark': remark,
        'status': status,
      };
}

/// 学校班级课表详情:查询:请求
class SchoolClassTimetableDetailQueryReq extends PagingQueryReq {
  final String classTimetableId, teacherId;
  final int weekVal, segment, subjectVal, status;

  SchoolClassTimetableDetailQueryReq({
    required this.classTimetableId,
    required this.teacherId,
    required this.weekVal,
    required this.segment,
    required this.subjectVal,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['weekVal'] = weekVal;
    map['segment'] = segment;
    map['subjectVal'] = subjectVal;
    map['teacherId'] = teacherId;
    map['status'] = status;
    return map;
  }
}

/// 学校班级课表详情:查询:响应
class SchoolClassTimetableDetailQueryRes
    extends PagingQueryRes<SchoolClassTimetableDetailItemRes> {
  SchoolClassTimetableDetailQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory SchoolClassTimetableDetailQueryRes.fromModel(
    final ResultModelRes res,
  ) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => SchoolClassTimetableDetailItemRes.fromMap(row),
    );
    return SchoolClassTimetableDetailQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

/// 学校班级课表详情:数据项:响应
class SchoolClassTimetableDetailItemRes {
  final String id, remark, teacherId, teacherAbbr;
  final int weekVal, segment, subjectVal, status;
  final DateTime? createdAt;

  const SchoolClassTimetableDetailItemRes({
    required this.id,
    required this.remark,
    required this.teacherId,
    required this.teacherAbbr,
    required this.weekVal,
    required this.segment,
    required this.subjectVal,
    required this.status,
    required this.createdAt,
  });

  factory SchoolClassTimetableDetailItemRes.fromMap(
    final Map<String, dynamic> map,
  ) =>
      SchoolClassTimetableDetailItemRes(
        id: map['id'] ?? '',
        remark: map['remark'] ?? '',
        teacherId: map['teacherId'] ?? '',
        teacherAbbr: map['teacherAbbr'] ?? '',
        weekVal: map['weekVal'] ?? 0,
        segment: map['segment'] ?? 0,
        subjectVal: map['subjectVal'] ?? 0,
        status: map['status'] ?? 0,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

/// 学校班级课表详情:加载:响应
class SchoolClassTimetableDetailInfoRes
    extends SchoolClassTimetableDetailItemRes with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  SchoolClassTimetableDetailInfoRes({
    required this.retCode,
    required this.retMessage,
    required SchoolClassTimetableDetailItemRes item,
  }) : super(
          id: item.id,
          remark: item.remark,
          teacherId: item.teacherId,
          teacherAbbr: item.teacherAbbr,
          weekVal: item.weekVal,
          segment: item.segment,
          subjectVal: item.subjectVal,
          status: item.status,
          createdAt: item.createdAt,
        );

  factory SchoolClassTimetableDetailInfoRes.fromModel(
    final ResultModelRes res,
  ) =>
      SchoolClassTimetableDetailInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: SchoolClassTimetableDetailItemRes.fromMap(res.toMap),
      );
}

/// 学校班级课表详情:新增:请求
class SchoolClassTimetableDetailAddReq {
  final String classTimetableId, remark, teacherId, teacherAbbr;
  final int weekVal, segment, subjectVal;

  const SchoolClassTimetableDetailAddReq({
    required this.classTimetableId,
    required this.remark,
    required this.teacherId,
    required this.teacherAbbr,
    required this.weekVal,
    required this.segment,
    required this.subjectVal,
  });

  Map<String, dynamic> toMap() => {
        'remark': remark,
        'teacherId': teacherId,
        'teacherAbbr': teacherAbbr,
        'weekVal': weekVal,
        'segment': segment,
        'subjectVal': subjectVal,
      };
}

/// 学校班级课表详情:修改:请求
class SchoolClassTimetableDetailModifyReq {
  final String id, remark, teacherId, teacherAbbr;
  final int weekVal, segment, subjectVal, status;

  const SchoolClassTimetableDetailModifyReq({
    required this.id,
    required this.remark,
    required this.teacherId,
    required this.teacherAbbr,
    required this.weekVal,
    required this.segment,
    required this.subjectVal,
    required this.status,
  });

  Map<String, dynamic> toMap() => {
        'remark': remark,
        'teacherId': teacherId,
        'teacherAbbr': teacherAbbr,
        'weekVal': weekVal,
        'segment': segment,
        'subjectVal': subjectVal,
        'status': status,
      };
}